<template>
  <div class="app-container">
    <el-card class="content-edit">
      <div slot="header">开票详情</div>
      <el-form label-width="120px">
        <el-form-item label="用户名">{{ form['userName'] }}</el-form-item>
        <el-form-item label="订单号">{{ form['orderSn'] }}</el-form-item>
        <el-form-item label="联系方式">{{ form['mobile'] }}</el-form-item>
        <el-form-item label="开票状态">{{ form['status']===1?'未开票':form['status']===2?'已开票':'已拒绝' }}</el-form-item>
        <el-form-item label="发票类型">{{ form['type']===1?'个人':'企业' }}</el-form-item>
        <el-form-item label="申请时间">{{ form['createTime'] }}</el-form-item>
        <el-form-item label="开票金额">{{ form['money'] }}元</el-form-item>
        <el-form-item label="纳税识别号">{{ form['dutyNumber'] }}</el-form-item>
        <el-form-item label="抬头">{{ form['headName'] }}</el-form-item>
        <el-form-item label="邮寄地址">{{ form['address'] }}</el-form-item>
        <el-form-item v-if="form['status']===1">
          <el-button type="danger" @click="changeStatus">立即开票</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
  export default {
    name: 'InvoiceDetails',
    data() {
      return {
        form: {
          // 用户名
          userName: ''
        }
      }
    },
    mounted(){
      this.form['id'] = this.$router.currentRoute.query['id'] || '';
      this.loadData();
    },
    methods: {
      // 加载用户信息
      loadData(){
        (async () => {
          const result = await this.$service.applicationGetInvoiceDetails({id: this.form['id']});
          if (result.code === 0) {
            Object.assign(this.form, result.data || {id: this.form['id']})
          }
        })();
      },
      // 切换状态
      changeStatus() {
        this.$confirm('你确定要通过这个发票吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
          callback: async (confirm) => {
            if (confirm === 'confirm') {
              // 创建一级分类
              const result = await this.$service.applicationChangeInvoiceStatus({
                id: this.form.id,
                status: 2
              });
              if (result.code === 0) {
                this.$message.success('通过成功~');
                this.$router.back();
              } else {
                this.$message.error(result.msg);
              }
            }
          }
        });
      }
    }
  }
</script>
